package com.example.mp.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mp.entity.Dept;
import com.example.mp.entity.TUser;
import com.example.mp.service.IDeptService;
import com.example.mp.util.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ykg
 * @since 2023-01-05
 */
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Resource
    private IDeptService deptService;
    /*
     * 查询，通用mapper*/
    @GetMapping
    public Result getAll(Integer current, Integer size, Dept dept){
        //List<TUser> list=userService.list();
        Page page=new Page(current,size);
        QueryWrapper queryWrapper= new QueryWrapper();
        if (StringUtils.isNotBlank(dept.getBname())){
            queryWrapper.like("bname",dept.getBname());
        }
        Page page1=deptService.page(page,queryWrapper);
        return new Result(page1);
    }
    /*
     * 删除，根据id 进行删除，通用mapper
     * */
    @DeleteMapping("{bid}")
    public Result delBuId(@PathVariable Integer bid){
        return  new Result(deptService.removeById(bid));
    }


    /*添加，和修改，通用mapper
     * */
    @PostMapping
    public Result addOrUpdate(Dept dept){
        return new Result(deptService.saveOrUpdate(dept));
    }
}

